/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#startTime").val(_start);
$("#endTime").val(_end);
laydate.render({
    elem: '#startTime',
    type: 'datetime',

});
laydate.render({
    elem: '#endTime' //指定元素
    , type: 'datetime',
});
initArea();
buttonShiro("export_Role");
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/CollectCardUserReportController/collectCardUserReportPage',
    height: $(window).height() - 200,
    pageSize: 100,
    pagination: true,
    pageList: [30, 50, 80, 100],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    showFooter: true,
    responseHandler: function (res) {
        return {
            "total": res.total,
            "rows": res.resultList
        };
    },
    onClickRow: function (row) {
        if (row.userAccount != null && row.userAccount != '') {
            $("#account_field"+row.userAccount+row.startDate).html(row.userAccount);
        }
    },
    columns: [[
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {field: 'userAccount', title: '会员编号', width: 90, align: 'center',
            formatter:function(v,o){
                return copyAddon(v) + (adminRole == 1 ? v :userAccountHidden(o.userAccount,o.userAccount+o.startDate));
            }},
        {field: 'userName', title: '会员名称', width: 90, align: 'center'},
        {
            field: 'startDate', title: '上传日期', width: 90, align: 'center'
        },
        {
            field: 'area', title: '销卡地区', width: 70, align: 'center',
            footerFormatter: function (value) {
                return "合计";
            }
        },
        {
            field: 'total', title: '收卡数', width: 70, align: 'center',
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].total);
                }
                return count + "";
            }
        },
        {field: 'ydFace', title: '移动<br/>收卡面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].ydFace);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'ydSettle', title: '移动<br/>结算面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].ydSettle);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'ltFace', title: '联通<br/>收卡面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].ltFace);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'ltSettle', title: '联通<br/>结算面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].ltSettle);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'dxFace', title: '电信<br/>收卡面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].dxFace);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'dxSettle', title: '电信<br/>结算面值', width: 70, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].dxSettle);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'face', title: '收卡<br/>总面值', width: 80, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].face);
                }
                return count.toFixed(4) + "";
            }},
        {field: 'settlePrice', title: '已结算<br/>总面值', width: 80, align: 'center', sortable: true,
            footerFormatter: function (value, o) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].settlePrice);
                }
                return count.toFixed(4) + "";
            }}
    ]]
});

$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    var require = (timeEnd - timeAdd) / (1 * 24 * 60 * 60 * 1000);
    if (require > 7) {
        layer.msg("时间间隔不能超过7天");
        return;
    }
    $("#dataTable").bootstrapTable("refresh");
});
//下载
$("#export").click(function () {
    window.location.href = "/CollectCardUserReportController/downLoad?" + $("#userReportForm").serialize()
})

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        userAccount: $("#userAccount").val(),
        area: $("#area").val(),
    };
}